package com.ljx.funchat.user.controller;

import com.ljx.funchat.common.domain.vo.req.CursorPageBaseReq;
import com.ljx.funchat.common.domain.vo.resp.ApiResult;
import com.ljx.funchat.common.domain.vo.resp.CursorPageBaseResp;
import com.ljx.funchat.common.utils.RequestHolder;
import com.ljx.funchat.user.domain.vo.req.UserFriendApplyReq;
import com.ljx.funchat.user.domain.vo.req.UserFriendHandleReq;
import com.ljx.funchat.user.domain.vo.resp.UserApplyResp;
import com.ljx.funchat.user.service.IUserApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/user/apply")
@Api(tags = "申请接口")
public class ApplyController {

    @Autowired
    private IUserApplyService applyService;

    @ApiOperation("申请添加联系人")
    @PostMapping
    public ApiResult<Void> apply(@Valid @RequestBody UserFriendApplyReq req){
        Long uid = RequestHolder.get().getUid();
        applyService.apply(uid, req);

        return ApiResult.success();
    }

    @ApiOperation("审核申请信息")
    @PutMapping
    public ApiResult<Void> handleApply(@Valid @RequestBody UserFriendHandleReq req){
        Long uid = RequestHolder.get().getUid();
        applyService.handleApply(uid, req);

        return ApiResult.success();
    }

    @ApiOperation("申请列表")
    @GetMapping("/page")
    public ApiResult<CursorPageBaseResp<UserApplyResp>> applyPage(@Valid CursorPageBaseReq req){
        Long uid = RequestHolder.get().getUid();

        return ApiResult.success(applyService.applyPage(uid, req));
    }


    @ApiOperation("删除申请记录")
    @DeleteMapping("/delete/{applyId}")
    public ApiResult<Void> deleteApply(@PathVariable("applyId") Long applyId){
        applyService.deleteApply(applyId);

        return ApiResult.success();
    }
}
